﻿using System;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

using Perseus;
using Perseus.Data;

namespace Hetymine.Executioner.Plugins.FTP {
    /// <summary>
    /// Interaction logic for FTPConfig.xaml
    /// </summary>
    public partial class FTPConfig : UserControl, IConfigurator<IniFile> {
        private IniFile _Config;

        public FTPConfig() {
            InitializeComponent();            

            this.cfgImageFilename.TextChanged += new System.Windows.Controls.TextChangedEventHandler(Filename_TextChanged);
            this.cfgTextFilename.TextChanged += new System.Windows.Controls.TextChangedEventHandler(Filename_TextChanged);
        }

        private void Filename_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e) {
            TextBox t = sender as TextBox;

            string filename = PIO.RemoveInvalidFileNameChars(t.Text);

            if (filename != t.Text) {
                t.Background = Brushes.LightPink;
            }
            else {
                t.Background = SystemColors.ControlLightLightBrush;

                switch (t.Name) {
                    case "cfgImageFilename":
                        this._Config.SetString("Plugins.FTP", "Default Image Filename", t.Text.Trim());
                        break;
                    case "cfgTextFilename":
                        this._Config.SetString("Plugins.FTP", "Default Text Filename", t.Text.Trim());
                        break;                    
                }
            }
        }

        public void InitializeConfig(IniFile config) {
            this._Config = config;
            this.cfgImageFilename.Text = this._Config.GetString("Plugins.FTP", "Default Image Filename", "clipboard");
            this.cfgTextFilename.Text = this._Config.GetString("Plugins.FTP", "Default Text Filename", "clipboard");            
        }
        public UserControl ConfigPanel { get { return this; } }
    }
}
